import uuid

from authentication.jwt import pwd_context
from domain.authentication import User


def form_user_body(user: User):
    tmp = user.dict()
    tmp['uuid'] = uuid.uuid5(
        uuid.NAMESPACE_DNS,
        f"{tmp['username']}:{tmp['email']}"
    ).hex
    tmp['emailVisibility'] = False
    tmp['verified'] = True
    tmp['passwordConfirm'] = user.password
    tmp['hashed_password'] = pwd_context.hash(user.password)
    return tmp


def form_updated_user_body(new_user: User, current_user: User):
    ret = form_user_body(new_user)
    ret['oldPassword'] = current_user.password
    return ret
